package com.bjpowernode.crm.handler;

import com.bjpowernode.crm.commons.contants.Contants;
import com.bjpowernode.crm.commons.domain.ReturnObject;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.lang.invoke.ConstantCallSite;

/**
 * 处理所有异常
 *
 * @author 刘逸晖
 */
@ControllerAdvice
@Component
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public ReturnObject handleException(Exception exception) {
        exception.printStackTrace();

        ReturnObject returnObject = new ReturnObject();

        returnObject.setCode(Contants.RETURN_OBJECT_CODE_FAIL);
        returnObject.setMessage("抱歉，服务器繁忙");

        return returnObject;
    }
}
